package com.java2110.utils;

import java.io.Serializable;
import java.util.List;

/**
 * @author admin
 * @since 2025-05-2025/5/23 13:59
 */
public class PageUtils<T> implements Serializable {
    private Integer currentPageNo = 0;
    private Integer pageSize = 3;
    private List<T> data;
    private Integer totalPageCount = 0;
    private Integer totalCount = 0;

    public PageUtils(Integer currentPageNo, Integer pageSize, List<T> data, Integer totalPageCount, Integer totalCount) {
        this.currentPageNo = currentPageNo;
        this.pageSize = pageSize;
        this.data = data;
        this.totalPageCount = totalPageCount;
        this.totalCount = totalCount;
    }

    public PageUtils() {
    }

    public Integer getCurrentPageNo() {
        return currentPageNo;
    }

    public void setCurrentPageNo(Integer currentPageNo) {
        this.currentPageNo = currentPageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public Integer getTotalPageCount() {
        return totalPageCount;
    }

    public void setTotalPageCount(Integer totalPageCount) {
        this.totalPageCount = totalPageCount;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
        this.setTotalPageCountByTotalCount();
    }

    private void setTotalPageCountByTotalCount() {
        if (null == this.totalCount || this.totalCount < 1) {
            this.totalPageCount = 0;
        }else if (this.totalCount % this.pageSize == 0) {
            this.totalPageCount = this.totalCount / this.pageSize;
        }else if (this.totalCount % this.pageSize != 0) {
            this.totalPageCount = this.totalCount / this.pageSize + 1;
        }
    }
}
